package com.education.user.service;


import com.education.user.mapper.BannerMapper;
import com.education.user.pojo.SysBanner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class BannerService {

    @Autowired
    private BannerMapper bannerMapper;


    public List<SysBanner> selectSysBannerList(SysBanner banner) {
        SysBanner sysBanner = new SysBanner();
        sysBanner.setSchoolId(banner.getSchoolId());
        List<SysBanner> select = bannerMapper.select(sysBanner);
        return select;
    }

    public SysBanner selectOne(Integer id) {
        Example example  =new Example(SysBanner.class);
        tk.mybatis.mapper.entity.Example.Criteria criteria =example.createCriteria();
        criteria.andEqualTo("id",id);
        return bannerMapper.selectOneByExample(example);
    }

    public int insertSysBanner(SysBanner banner) {
        return bannerMapper.insert(banner);
    }

    public int updateSysBanner(SysBanner sysBanner) {
        SysBanner sysBanner1 = new SysBanner();
        //id
        if(sysBanner.getId()!=null){
            sysBanner1.setId(sysBanner.getId());
        }
        //名称
        if(sysBanner.getName()!=null && !"".equals(sysBanner.getName())){
            sysBanner1.setName(sysBanner.getName());
        }
        //图片
        if(sysBanner.getUrl()!=null&&!"".equals(sysBanner.getUrl())){
            sysBanner1.setUrl(sysBanner.getUrl());
        }
        //门户是否显示
        if(sysBanner.getIsdisplay()!=null&&!"".equals(sysBanner.getIsdisplay())){
            sysBanner1.setIsdisplay(sysBanner.getIsdisplay());
        }
        //排序
        if(sysBanner.getSort()!=null){
            sysBanner1.setSort(sysBanner.getSort());
        }
        return bannerMapper.updateByPrimaryKeySelective(sysBanner1);
    }

    public int deleteSysBannerById(String id) {
        return bannerMapper.deleteByPrimaryKey(id);
    }

    //升序
    public List<SysBanner> selectSysBannerBySortAsc(String id) {
        return bannerMapper.selectSysBannerBySortAsc(id);
    }

    //降序
    public List<SysBanner> selectSysBannerBySortDesc(String id) {
        return bannerMapper.selectSysBannerBySortDesc(id);
    }
}
